local lao__cangxin = fk.CreateSkill{
  name = "lao__cangxin",
  tags = { Skill.Compulsory },
}

Fk:loadTranslationTable{
  ["lao__cangxin"] = "藏心",
  [":lao__cangxin"] = "锁定技，摸牌阶段开始时，你展示牌堆底三张牌并摸其中<font color='red'>♥</font>牌数的牌。"..
  "当你受到伤害时，你展示牌堆底三张牌并弃置其中任意张牌，令伤害值-X（X为以此法弃置的<font color='red'>♥</font>牌数）。",

  ["#lao__cangxin-discard"] = "藏心：你可以弃置其中任意张牌，每弃置一张<font color='red'>♥</font>牌伤害-1",

  ["$lao__cangxin1"] = "红豆藏香米，共裹一青叶，其味佳否？",
  ["$lao__cangxin2"] = "手折素柳织祥瑞， 且将艾荷寄清风。",
}

lao__cangxin:addEffect(fk.EventPhaseStart, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(lao__cangxin.name) and player.phase == Player.Draw
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = room:getNCards(3, "bottom")
    room:turnOverCardsFromDrawPile(player, cards, lao__cangxin.name)
    room:delay(1500)
    local n = #table.filter(cards, function (id)
      return Fk:getCardById(id).suit == Card.Heart
    end)
    if n > 0 then
      player:drawCards(n, lao__cangxin.name)
    end
    room:returnCardsToDrawPile(player, cards, lao__cangxin.name, "bottom")
  end,
})
lao__cangxin:addEffect(fk.DamageInflicted, {
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(lao__cangxin.name)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = room:getNCards(3, "bottom")
    room:turnOverCardsFromDrawPile(player, cards, lao__cangxin.name)
    local to_throw = room:askToChooseCards(player, {
      target = player,
      min = 0,
      max = 3,
      flag = { card_data = {{ "Bottom", cards }} },
      skill_name = lao__cangxin.name,
      prompt = "#lao__cangxin-discard",
    })
    if #to_throw > 0 then
      local n = #table.filter(to_throw, function (id)
        return Fk:getCardById(id).suit == Card.Heart
      end)
      data:changeDamage(-n)
      room:moveCards {
        ids = to_throw,
        toArea = Card.DiscardPile,
        moveReason = fk.ReasonPutIntoDiscardPile,
        skillName = lao__cangxin.name,
        proposer = player,
      }
    end
    room:returnCardsToDrawPile(player, cards, lao__cangxin.name, "bottom")
  end,
})

return lao__cangxin
